Presenting Event Data

From Documentation


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


Having constructed a memory model we can now go ahead and adjust this code to work in a functional ZK Calendar application. The code below is a fully working readonly calendar which creates random events when the button is clicked. This gives a full example using a memory model with ZK Calendar.

<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
    <window height="100%" width="100%">
        <zscript>
            <![CDATA[
                SimpleCalendarModel scm = new SimpleCalendarModel();
 
                public void addToModel(CalendarEvent ce) {
                    scm.add(ce);
                }
 
                public CalendarEvent createRandomEvent() {
                    SimpleCalendarEvent sce = new SimpleCalendarEvent();
                    Random generator = new Random();
 					 
                    long timeNow = System.currentTimeMillis();
                    long roundedTime = timeNow - (timeNow % 1000);
 
                    java.util.Calendar cal = java.util.Calendar.getInstance();
 
                    cal.setTimeInMillis(roundedTime);
                    cal.add(java.util.Calendar.HOUR, -(generator.nextInt(3) + 2));
                    sce.setBeginDate(cal.getTime());
                    System.out.println(cal.getTime());
 
                    cal.setTimeInMillis(roundedTime);
                    cal.add(java.util.Calendar.HOUR, generator.nextInt(3) + 1);
                    sce.setEndDate(cal.getTime());
                    System.out.println(cal.getTime());
 
                    //The color Strings should only be colors
                    //that CSS accept
                    sce.setContentColor("red");
                    sce.setHeaderColor("red");
 
                    sce.setContent("This is the content of the event");
                    sce.setTitle("This is the title of the event");
 
                    //is this event locked?
                    sce.setLocked(false);
 
                    return sce;
                }
 
                public void createData() {
                    scm = new SimpleCalendarModel();
 
                    for(int i=0; i<3; i++) {
                        CalendarEvent ce = createRandomEvent();
                        addToModel(ce);
                    }
 
                    calendar.setModel(scm);
                }
            ]]>
        </zscript>
	<calendars id="calendar" height="80%" firstDayOfWeek="Sunday"
                   timeZone="California=PDT-8" mold="default" readonly="true" />
        <button id="createData" label="Create Data" onClick="createData()" />
    </window>
</zk>


The above code's output is shown below.

ZKCalEss MemoryModelResult.png


The example project is at Github


Last Update : 2021/02/02

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.